package definite.Guide.Book.JColorChooser;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;

import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.FontUIResource;

public class ColorSample {

	public static void main(String[] args) {
		Runnable r = new Runnable() {

			@Override
			public void run() {
				JFrame.setDefaultLookAndFeelDecorated(true);
				JFrame frame = new JFrame("Color Chooser Sample");
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

				final JLabel label =
					new JLabel("The Guide to Java Swing", JLabel.CENTER);
				label.setFont(new FontUIResource("Serif", Font.BOLD
					| Font.ITALIC, 48));
				frame.add(label, BorderLayout.NORTH);

				final JColorChooser clChooser =
					new JColorChooser(label.getBackground());
				TitledBorder border =
					new TitledBorder(null, "Color Chooser", TitledBorder.TOP,
							TitledBorder.CENTER, new Font("San-Serif",
									Font.BOLD | Font.ITALIC, 16), Color.RED);
				label.setBorder(border);

				frame.add(clChooser, BorderLayout.CENTER);
				frame.pack();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		};

		EventQueue.invokeLater(r);
	}

}

/*TheJColorChooseruses a ColorSelectionModelas its data model. As the following interface 
definition shows, the data model includes a single property, selectedColor, for managing the 
state of the color chooser. */

/*public interface ColorSelectionModel {
// Listeners
public void addChangeListener(ChangeListener listener);
public void removeChangeListener(ChangeListener listener);
// Properties
public Color getSelectedColor();
public void setSelectedColor(Color newValue);
}
*/

// activating Jcolor choosing
/*ColorSelectionModel model = clChooser.getSelectionModel();
ChangeListener changed = new ChangeListener() {

	@Override
	public void stateChanged(ChangeEvent e) {
		Color newBackGround = clChooser.getColor();
		label.setBackground(newBackGround);
	}
};
model.addChangeListener(changed);*/

